import React, { Component } from 'react';
import { Form, Icon, Input, Button } from 'antd';
import {register} from "../api/index";
class Login extends Component {
    handleSubmit = e => {
        e.preventDefault();
        this.props.form.validateFields(async (err, values) => {
            if (!err) {
                console.log('Received values of form: ', values);
                let res = await register(values)
                if(res.data.code===2){
                    this.props.history.push("/login")
                }
            }
        });
    };
    render() {
        const { getFieldDecorator } = this.props.form;
        return (
            <div className="login">
            <Form onSubmit={this.handleSubmit} className="login-form">
                <Form.Item>
                    {getFieldDecorator('name',)(
                        <Input
                            prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
                            placeholder="用户名"
                        />,
                    )}
                </Form.Item>
                <Form.Item>
                    {getFieldDecorator('pwd',)(
                        <Input
                            prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
                            type="password"
                            placeholder="密码"
                        />,
                    )}
                </Form.Item>
                <Form.Item>
                    <Button type="primary"  htmlType="submit" style={{ marginLeft: "20px" }} className="login-form-button">
                        注册
                    </Button>
                </Form.Item>
            </Form>
            </div>
        );
    }
}

export default Form.create({ name: 'normal_login' })(Login);